<?php

/*
* This file is part of the symfony package.
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

/**
 * sfWidgetFormI18nSelectCountry represents a country HTML select tag.
 *
 * @package    symfony
 * @subpackage widget
 * @author     Fabien Potencier <fabien.potencier@symfony-project.com>
 * @version    SVN: $Id: sfWidgetFormI18nSelectCountry.class.php 11842 2008-09-29 10:53:28Z fabien $
 */
class sfWidgetFormI18nSelectCountryWithArabRegion extends sfWidgetFormI18nChoiceCountry
{

	/**
   * Constructor.
   *
   * Available options:
   *
   *  * culture:   The culture to use for internationalized strings (required)
   *  * countries: An array of country codes to use (ISO 3166)
   *  * add_empty: Whether to add a first empty value or not (false by default)
   *               If the option is not a Boolean, the value will be used as the text value
   *
   * @param array $options     An array of options
   * @param array $attributes  An array of default HTML attributes
   *
   * @see sfWidgetFormSelect
   */
	protected function configure($options = array(), $attributes = array())
	{
		parent::configure($options, $attributes);
		
		$this->addOption('arab_region_only',false);
		$arab_countries_bool = $options['arab_region_only'];

		$countries = $this->getOption('choices');

		$arab_countries = array(
		'JO'=>$countries['JO']
		, 'SA'=>$countries['SA']
		, 'AE'=>$countries['AE']
		, 'EG'=>$countries['EG']
		, 'SY'=>$countries['SY']
		, 'KW'=>$countries['KW']
		, 'QA'=>$countries['QA']
		, 'IL'=>$countries['IL']
		, 'OM'=>$countries['OM']
		, 'DJ'=>$countries['DJ']
		, 'TN'=>$countries['TN']
		, 'YE'=>$countries['YE']
		, 'MA'=>$countries['MA']
		, 'SO'=>$countries['SO']
		, 'DZ'=>$countries['DZ']
		, 'BH'=>$countries['BH']
		, 'LB'=>$countries['LB']
		, 'LY'=>$countries['LY']
		, 'MR'=>$countries['MR']
		);
		unset(
		$countries['JO']
		, $countries['SA']
		, $countries['AE']
		, $countries['EG']
		, $countries['SY']
		, $countries['KW']
		, $countries['QA']
		, $countries['IL']
		, $countries['OM']
		, $countries['DJ']
		, $countries['TN']
		, $countries['YE']
		, $countries['MA']
		, $countries['SO']
		, $countries['DZ']
		, $countries['BH']
		, $countries['LB']
		, $countries['LY']
		, $countries['MR']
		);


		$addEmpty = isset($options['add_empty']) ? $options['add_empty'] : false;
		if (false !== $addEmpty)
		{
			$arab_countries = array_merge(array('' => true === $addEmpty ? '' : $addEmpty), $arab_countries);
			unset($countries['']);
		}

		$countries_with_arab[__('Arab countries')] = $arab_countries;
		$countries_with_arab[__('Other countries')] = $countries;

		if($arab_countries_bool){
			$this->setOption('choices', $arab_countries);
		}else{
			$this->setOption('choices', $countries_with_arab);
		}
	}
}
